#include "StdAfx.h"
#include "NetServer.h"
#include "tinyxml.h"
#include "tconfigsetting.h"

USING_LIBSPACE

namespace nettransport
{


	CNetServer::CNetServer(void)
	{
	}

	CNetServer::~CNetServer(void)
	{
	}

	bool CNetServer::Initialize( void* pParam )
	{
		try
		{
			TConfigSetting setting ;
			setting.LoadConfig("ICE.CPPNetTransportServer.xml");
			std::string port = setting["configuration"]["port"].EleVal();
			
			
			m_ic = Ice::initialize();

			Ice::ObjectAdapterPtr adapter= m_ic->createObjectAdapterWithEndpoints("IBasicCall", std::string("default -p ") + port);
			Ice::ObjectPtr object = new nettransport::CBasicCallImp;
			adapter->add(object,m_ic->stringToIdentity("IBasicCall"));

			adapter->activate();

			

			return true;
		}
		catch (const Ice::Exception& e) 
		{
			std::cerr<<e.what()<<std::endl;
		}
		return false;
	}

	void CNetServer::UnInitialize()
	{
		if (m_ic) 
		{
			try 
			{
				m_ic->destroy();
			} catch (const Ice::Exception& e) 
			{
				std::cerr << e << std::endl;	
			}
		}

	}


};